package tool;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class SystemUtils {

	private static InputStream configInputStream = null;
	private static Properties prop = null;
	private static File rootConfig = null;
	
	public interface Propskey {
		String SERVER_PORT = "server.port";
		String SERVER_CONNECTION_MAX="server.connection.max";
	}
	
	private static void init() {
		try {
			rootConfig = path("config.properties");
			configInputStream = new FileInputStream(rootConfig);
			prop = new Properties();
			prop.load(configInputStream);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private static File path(String path) {
		String prefix = SystemUtils.class.getResource("/").getPath();
		return new File(prefix+path);
	}
	
	
	
	public static String getProperty(String key) {
		if(prop==null) {
			init();
		}
		return prop.getProperty(key);
	}
	
	public static int getIntProperty(String key) {
		if(prop==null) {
			init();
		}
		return Integer.valueOf(prop.getProperty(key));
	}
	
	public static double getDoubleProperty(String key) {
		if(prop==null) {
			init();
		}
		return Double.valueOf(prop.getProperty(key));
	}
}
